// pages/enlistManage/enlistManage.js
const app = getApp()
import Dialog from '../../dist/dialog/dialog';
const timeFormatting = require('../../utils/timeFormatting.js');
const CryptoJS = require('../../utils/aes-jia.js')
var timestamp = Date.parse(new Date()) / 1000; 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    createUid:'',
    define: false,
    choice:false,
    singleRefund:false,
    list:[],
    lists:[],
    // 支付类型
    chooseConsume:'',
    //报名总人数
    applyCount:'',
    //已通过人数
    check: '',
    //待审核人数
    noCheck: '',
    //不参加人数
    noJoin: '',
    //签到人数
    signInNum: '',
    //已查看
    browseNum:'',
    //收款
    totalMoney:'',
    // 已退款钱数
    refunded:'',
    hiddenmodal: false,
    count:0,
    inputAmount:'',
    perCapita:'',
    userList:[],
    exportList:[],
    inputRefund:'',
    useid:'',
    isToExamine:false,
    userInfo:{},
    isCreate:false,
    createUid:'',
    participantId:'',
    singleRefundClick:false,
    batchRefundClick:false,
    listType:1,
    averageNum:'',
    isClick:false,
    personalPaymentAmount:'',
    isstatus:'',
    showPayPwdInput: false,  //是否展示密码输入层
    pwdVal: '',  //输入的密码
    payFocus: true, //文本框焦点
    prepaymentRecordId: '',
    whetherSetPayPwd: '',
    yamount:'',
    ynum:'',
    enrollment:'',
    isLook:false,
    isSd:false,
    pageNumber:1,
    pageSize:10,
    totalPages:'',
    iskong:true,
    isEnrollment:0,
  },
  //点击事件
  listType(e){
    console.log('点击', this.data.iskong)
    if(this.data.iskong){
      var type = e.currentTarget.dataset.id
      console.log('点击')
      this.setData({
        iskong:false,
        lists:[],
        listType: type,
        pageNumber: 1,
        callback: function () {
        }
      })
      this.onShow()
    }
  },
  //获取列表
  getlist(){
    var that = this;
    app.req({
      url: "wechat/act/participation/participantListDetail",
      method: "post",
      data: {
        activityId: that.data.id,
        type: 3,
        pageNumber: that.data.pageNumber,
        pageSize: that.data.pageSize,
      },
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            lists: that.data.lists.concat(res.data.list.rows),
            totalPages: res.data.list.totalPages,
            applyCount: res.data.check,
            browseNum: res.data.browseNum,
            signInNum: res.data.signInNum,
            createUid: res.data.createUid,
            iskong: true,
          })
          console.log("人员列表", res)

        }else{
          that.setData({
            iskong: true,
          })
        }
      }
    })
  },
  getlists() {
    var that = this;
    // that.setData({
    //   lists:[]
    // })
    app.req({
      url: "wechat/act/participation/participantListDetail",
      method: "post",
      data: {
        activityId: that.data.id,
        type: 4,
        pageNumber: that.data.pageNumber,
        pageSize: that.data.pageSize,
      },
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            lists: that.data.lists.concat(res.data.list.rows),
            totalPages: res.data.list.totalPages,
            iskong: true,
          })
          console.log("查看人员列表", res)

        } else {
          that.setData({
            iskong: true,
          })
        }
      }
    })
  },
  callup:function(e) {
    var phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  choiceTap: function (){
    app.TestBuriedPoint('yqlw_details_choice')
    this.setData({
      choice:true
    })
  },


  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },

  //删除元素
  remove: function (array, val) {
    for (var i = 0; i < array.length; i++) {
      if (array[i] == val) {
        array.splice(i, 1);
      }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      id: options.id
    })
    if (options.isEnrollment==1){
      that.setData({
        isEnrollment: 1
      })
    }
    console.log('huodog', that.data.id,options.id)
    app.getUserInfo(function (userInfo) {
      console.log("options第一次")
      that.toggle("userInfo", userInfo);
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.TestBuriedPoint2("yqlw_details_signup,yqlw_details_adopt,yqlw_details_examine,yqlw_details_refuse,yqlw_details_pv")
    if (this.data.listType == 1) {
      this.setData({
        lists: [],
       
      })
      this.getlist()
    } else if (this.data.listType == 2) {
      this.setData({
        lists: [],
        // iskong: true,
      })
      this.getlists()
    }
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
     var that = this
    if (that.data.totalPages>that.data.pageNumber){
      that.setData({
        pageNumber: that.data.pageNumber + 1
      })
      if (this.data.listType == 1) {
        this.getlist()
      } else if (this.data.listType == 2) {
        this.getlists()
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})